import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
import router from "./router";
import Api from "./Api";

const app = createApp(App);

// 前置路由守卫to当前所需要跳转的路径
router.beforeEach((to) => {
  // 在这里添加你的逻辑
  const token = localStorage.getItem("h5_token");
  // 判断是否非登录页面token是否存在
  if (!token && to.path !== "/login") {
    return "/login";
  } else if (token && to.path === "/login") {
    return "/";
  } else {
    return true;
  }
});

// 将api挂载在全局
app.config.globalProperties.$api = Api;
app.use(router);
app.mount("#app");
